var app = angular.module('ZJPC');

app.controller('IndoorController', ['$rootScope', '$scope', 'ModalService', 'CesiumService', 
  function($rootScope,  $scope, ModalService, CesiumService) {

  	var buildData = ['综合楼', 'jj+115', '学生公寓', 'jj+7', '战训楼', 'jj+291', '专家楼', 'jj+139', '警官苑', 'jj+138', '食堂', 'jj+111', '图书馆', 'jj+141', '警务保障楼', 'jj+63'];
  	$scope.dataSources = {
  		wifi: ['openModalFunc', 'ww+4', 'templates/region/wifi.html', 'WifiController'],
  		monitor: ['openModal', 'jj+4'],
  		face: ['openModalFunc', 'rr+4', 'templates/region/face.html', 'FaceController'],
  		bayonet: ['openModalFunc', 'yy+4', 'templates/region/bayonet.html', 'BayonetController']
  	}

  	$scope.$on("check_build_name", function(e, value) {
  		// console.log(value,2);
		for (var i = 0; i < buildData.length; i++){
			if (value == buildData[i]){
				$scope.dataSources.monitor[1] = buildData[i+1];
			}
		}
  	})

	$scope.i = function(value){
		ModalService[$scope.dataSources[value][0]]($scope.dataSources[value][1], $scope.dataSources[value][2], $scope.dataSources[value][3]);
	}

	function choose (func, param, html, controller){
		ModalService[func](param, html, controller);
	}

	$scope.$on("belong", function(e, value) {
		// console.log(value,8);
		var build = value.belong[value.buildName];

		$scope.insideBuilding = [];
		if(build.wifi.length > 0){
			$scope.insideBuilding.push('wifi');
			/*var checkId = [];
			for(var i = 0; i < build.wifi.length; i++){
				checkId.push('ww+' + build.wifi[i].id);
			}
			$scope.dataSources[0][1] = checkId;*/
		}
		if(build.monitor.length > 0){
			$scope.insideBuilding.push('monitor');
		}
		if(build.face.length > 0){
			$scope.insideBuilding.push('face');
		}
		if(build.bayonet.length > 0){
			$scope.insideBuilding.push('bayonet');
		}
		

		$scope.$apply();

	})


}])